package com.fduss.mazegame.client.gui.fxgui;

import com.fduss.mazegame.client.Localizer;
import com.fduss.mazegame.client.MsgToUsr;
import javafx.scene.control.*;

/**
 * @author Duocai Wu
 * @Date 2017/11/13
 * @Time 16:58
 */
class MyMenuBar extends MenuBar {

    MyMenuBar(Localizer localizer, FxGui app) {
        super();
        // add file menu
        Menu menuFile = new Menu("File");
        MenuItem loadItem = new MenuItem("Load");
        MenuItem saveItem = new MenuItem("Save");
        menuFile.getItems().addAll(loadItem, saveItem);

        // add settings menu
        Menu menuSetting = new Menu("Settings");
        Menu themeMenu = new Menu("Theme");
        ToggleGroup themeGroup = new ToggleGroup();
        RadioMenuItem snowTheme = new RadioMenuItem("snow");
        snowTheme.setUserData(Theme.snow);
        snowTheme.setToggleGroup(themeGroup);
        RadioMenuItem grassTheme = new RadioMenuItem("grass");
        grassTheme.setUserData(Theme.grass);
        grassTheme.setToggleGroup(themeGroup);
        if (FxGui.theme == Theme.snow)
            snowTheme.setSelected(true);
        else
            grassTheme.setSelected(true);
        //Processing menu item selection
        themeGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
            if (new_toggle != null) {
                app.changeTheme((Theme) new_toggle.getUserData());
            }
        });
        themeMenu.getItems().addAll(snowTheme, grassTheme);
        menuSetting.getItems().add(themeMenu);

        // add help menu
        Menu menuHelp = new Menu("Help");
        MenuItem howToPlay = new MenuItem("How to Play");
        howToPlay.setOnAction(event -> {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setContentText(localizer.get(MsgToUsr.HELP));
            alert.showAndWait();
        });
        menuHelp.getItems().add(howToPlay);
        this.getMenus().addAll(menuFile, menuSetting, menuHelp);
    }
}
